package net.messagenet.mazor.ejb.facade;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.ejb.Local;

import net.messagenet.mazor.DO.CustomerDO;
import net.messagenet.mazor.DO.DpaDO;
import net.messagenet.mazor.DO.DpaProductDO;
import net.messagenet.mazor.DO.PosDO;
import net.messagenet.mazor.DO.PosProductDO;
import net.messagenet.mazor.exception.MZRApplicativeException;
import net.messagenet.mazor.exception.MZRInternalServerException;
import net.messagenet.mazor.infra.cache.UserCacheManager;

/**
 * 
 * This interface is used as an entry point to the mazor system
 * 
 * @author Idan
 *
 */

@Local
public interface MZRFacadeLocal {
	
	/**
	 * creates a DPA request according the data in the data object 
	 * the system will save the data create an excel document that will be send
	 * to the user
	 * 
	 * if the dpa contains id then it is loaded, changed and marked as not draft
	 * 
	 * @param dpa dpa data object according to which the excel will be build
	 * @throws MZRInternalServerException
	 * @throws MZRApplicativeException
	 */
	public void createDPARequest(DpaDO dpa) throws MZRInternalServerException,MZRApplicativeException;
	/**
	 * This method saves the dpa object as a draft that can loaded later
	 * 
	 * @param dpa - dpa data object 
	 * @throws MZRInternalServerException
	 * @throws MZRApplicativeException
	 */
	public void saveDPADraft(DpaDO dpa) throws MZRInternalServerException,MZRApplicativeException;

	/**
	 * This method returns the user cache manger for client usage
	 * 
	 * @return a read only cache manager
	 * @throws MZRInternalServerException 
	 */
	public UserCacheManager getUserCacheManager() throws MZRInternalServerException;

	/**
	 * This method takes a path of an returning DPA request excel file
	 * and update the system with the returning information.
	 * if the DPA sheet doesn't contain DPA ID from dialogic then the DPA is marked as
	 * not approved
	 * 
	 * @param path the full path of the uploaded file
	 */
	public void loadDPAAnswerSheet(String path) throws MZRInternalServerException,MZRApplicativeException;
	/**
	 * This method gets all the open dpas that didn't expired and has more product to report
	 * 
	 * @return a map of dpas keyed by the dialogic item #
	 * @throws MZRInternalServerException
	 * @throws MZRApplicativeException
	 */
	public Map<String,DpaDO> getAllApprovedDPAs()throws MZRInternalServerException,MZRApplicativeException;

	/**
	 * 
	 * This method creates a new POS report
	 * 
	 * @param posDo pos data object
	 * @throws MZRApplicativeException 
	 * @throws MZRInternalServerException 
	 */
	public void createNewPOSRequest(PosDO posDo) throws MZRInternalServerException, MZRApplicativeException;

	/**
	 * This method creates a new customer in the system if it is already exists this method 
	 * Updates the changes.
	 * 
	 * @param customer
	 * @throws MZRInternalServerException 
	 */
	public void createOrEditCustomer( CustomerDO customer) throws MZRInternalServerException;

	
	/**
	 * This method returns all the products in the dpa that were reported in the pos and didn't
	 * payment
	 * 

	 * @param fromDate
	 * @param toDate
	 * @return a list of all the products
	 * @throws MZRInternalServerException 
	 */
	public List<DpaProductDO> getDPAReportedProducts(Date fromDate, Date toDate) throws MZRInternalServerException;

	/**
	 * This method updates the paid quantity in the dpa products after refunding
	 * 
	 * 
	 * @param products
	 * @throws MZRInternalServerException 
	 */
	public void updatePaidProducts(List<DpaProductDO> products) throws MZRInternalServerException;
	/**
	 * returns all the dpa drafts
	 * 
	 * @return a list of all dpa defined as drafts
	 * @throws MZRInternalServerException 
	 */

	public List<DpaDO> getDPADrafts() throws MZRInternalServerException;

	/**
	 * given a list of dpa product this method removes those products form the DB
	 * 
	 * 
	 * @param removePrds
	 * @throws MZRInternalServerException 
	 */
	public void removeDPAProducts( List<DpaProductDO> removePrds) throws MZRInternalServerException;
	/**
	 * returns all the pos drafts
	 * 
	 * @return a list of all pos defined as drafts
	 * @throws MZRInternalServerException 
	 */
	public List<PosDO> getPOSDrafts() throws MZRInternalServerException;

	/**
	 * This method saves the dpa object as a draft that can loaded later
	 * 
	 * @param pos pos data object
	 * @throws MZRInternalServerException
	 */
	public void savePOSDraft( PosDO pos) throws MZRInternalServerException;
	/**
	 * given a list of pos product this method removes those products form the DB
	 * 
	 * 
	 * @param removePrds
	 * @throws MZRInternalServerException 
	 */
	public void removePOSProducts( List<PosProductDO> removePrds) throws MZRInternalServerException;

	/**
	 * gets all the dpas that are not closed (has didn't receive full payment for all the products )
	 * 
	 * @return a map of dpas keyed by the dpa id in the mazor system
	 */
	public Map<Integer, DpaDO> getAllNotClosedDPAs() throws MZRInternalServerException;

	/**
	 * This method returns all the closed dpa and not approved dpas
	 * 
	 * @return
	 * @throws MZRInternalServerException 
	 */
	public List<DpaDO> getClosedAndNotApprovedDPAs() throws MZRInternalServerException;
	/**
	 * This method returns all the DPAs in the system form draft to new DPA mapped by id
	 * 
	 * @return
	 * @throws MZRInternalServerException 
	 */
	public Map<Integer, DpaDO> getAllDPAs() throws MZRInternalServerException;

	
	
}
